/*
 * FileUtils.cpp
 *
 *  Created on: Apr 15, 2012
 *      Author: gonzalo
 */

#include "FileUtils.h"


SDL_Surface* FileUtils::loadImage(std::string path){

	if(!FileChecker::fileExists(path)){
		Logger::log("FileUtils","loadImage","El archivo no existe!. File:" + path);
		return NULL;
	}

	SDL_Surface* surface = NULL;

	SDL_Surface* aux = NULL;
	char* c_path = new char[path.size() + 1];
	c_path[0] = '\0';
	strcpy	(c_path, path.c_str());
	aux = IMG_Load(c_path);
	delete[] c_path;

	if (aux != NULL) {
        //Create an optimized surface
		surface = SDL_DisplayFormat( aux );
		//surface = SDL_DisplayFormatAlpha(aux);
		SDL_FreeSurface(aux);
	}

	return surface;

}
